package com.andy.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Iterator;

/**
 * model工具类
 * @author Bob.wei
 *
 * 2018年5月13日下午6:34:48
 */
public class ModelUtil {
	
	public static Object fillNullValueField(Object targetObj) {
		Object res = null;
		
		Field[] declaredFields = targetObj.getClass().getDeclaredFields();
		
		for (int i = 0; i < declaredFields.length; i++) {
			Field field = declaredFields[i];
			field.setAccessible(true);
			try {
				if(field.getType().isPrimitive() == Boolean.FALSE && field.get(targetObj) == null ) {
					if(field.getType() == Integer.class) {
						field.setInt(targetObj, 0);
					} else if(field.getType() == Long.class) {
						field.setLong(targetObj, 0);
					} else if(field.getType() == String.class) {
						field.set(targetObj, "");
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		return res;
	}
	
	public static void main(String[] args) {
//		fillNullValueField(user);
		
	}
	

}
